package diamondServer.businesslogic.resource.loader;

import java.net.URL;
import java.net.URLClassLoader;

import diamondServer.resources.Message;
import diamondServer.resources.Service;



/**
 * This ClassLoader loads classes like {@link URLClassLoader} do, except
 * the case when the classes are {@link Message} or {@link Service} class. 
 * 
 * <p>In this case Message's and Service's ClassLoader will load the class.</p>
 * 
 * <p>The parent of this ClassLoader is null, i.e. BootStrap ClassLoader.</p>
 * 
 */
public class SpecialURLClassLoader
	extends URLClassLoader
{

	/**
	 * The parent of the ClassLoader is null
	 */
	public SpecialURLClassLoader(URL[] urls)
	{
		super(urls,null);
	}
	
	/**
	 * loads classes like {@link URLClassLoader} do, except
	 * the case when the classes are {@link Message} or {@link Service}. 
	 * 
	 * <p>
	 * In this case Message's and Service's ClassLoader will load the 
	 * class.</p>
	 */
	@Override
	public Class<?> loadClass(String sClassName) throws ClassNotFoundException
	{
		if(sClassName.equals(Message.class.getName()))
			return Message.class.getClassLoader()
				.loadClass(Message.class.getName());
		
		if(sClassName.equals(Service.class.getName()))
			return Service.class.getClassLoader()
				.loadClass(Service.class.getName());
		
		return super.loadClass(sClassName);
	}
	
}
